package com.tms.basic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tms.basic.pojo.dto.UserDto;
import com.tms.basic.pojo.req.UserReq;
import com.tms.basic.pojo.vo.UserVo;
import com.tms.basic.service.UserService;
import com.tms.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    
    @Autowired
    private UserService userService;
    
    /**
     * 获取用户信息
     *
     * @param username 用户名
     * @return 用户信息
     */
    @GetMapping("/info/{username}")
    public R<UserVo> getUserInfo(@PathVariable("username") String username) {
        return R.success(userService.getUserInfo(username));
    }
    
    @PostMapping("/listUser")
    public R<Page<UserVo>> listUser(@RequestBody UserReq userReq) {
        return R.success(userService.listUsers(userReq));
    }
    
    @PostMapping("/addUser")
    public R<Boolean> addUser(@RequestBody UserDto userDto) {
        return R.success(userService.createUser(userDto));
    }
    
    @PostMapping("/updateUser")
    public R<Boolean> updateUser(@RequestBody UserDto userDto) {
        return R.success(userService.updateUser(userDto));
    }
    
    @PostMapping("/deleteUser/{id}")
    public R<Boolean> deleteUser(@PathVariable Long id) {
        return R.success(userService.deleteUser(id));
    }
    
    @PostMapping("/updateUserStatus")
    public R<Boolean> updateUserStatus(@RequestBody UserReq userReq) {
        return R.success(userService.updateUserStatus(userReq.getId(), userReq.getStatus()));
    }
    
    @PostMapping("/resetUserPassword")
    public R<Boolean> resetUserPassword(@RequestBody UserReq userReq) {
        return R.success(userService.resetUserPassword(userReq.getId(), userReq.getPassword()));
    }
}